#[macro_use] extern crate rocket;
use rocket::fs::FileServer;

#[get("/")]
fn index() -> &'static str {
    "Hello, world!"
}

#[get("/delay/<seconds>")]
async fn delay(seconds: u64) -> String {
    rocket::tokio::time::sleep(rocket::tokio::time::Duration::from_secs(seconds)).await;
    format!("Waited for {} seconds", seconds)
}

#[get("/hello/<name>/<age>/<cool>")]
fn hello(name: &str, age: u8, cool: bool) -> String {
    if cool {
        format!("You're a cool {} year old, {}!", age, name)
    } else {
        format!("{}, we need to talk about your coolness.", name)
    }
}

#[get("/<_..>", rank= 2)]
fn everything() -> &'static str {
    "Hey, you're here."
}

#[get("/foo/<_>/bar")]
fn foo_bar() -> &'static str {
    "Foo _____ bar!"
}

#[rocket::main]
async fn main() -> Result<(), rocket::Error> {
    let _rocket = rocket::build()
        .mount("/", routes![index, delay, hello, everything, foo_bar])
        .mount("/public", FileServer::from("/www/static"))
        .launch()
        .await?;
    Ok(())
}